﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Baimasoft.Manage.SqlServerDAL;

public partial class BBS_BbsLogon : System.Web.UI.Page
{
    user MyUser = new user();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
          
        }

    }
    protected void Button1_ServerClick(object sender, EventArgs e)
    {
        string sUserID =  UserID.Value.ToString().Trim();
        string spassword = password.Value.ToString().Trim();
        int iCookieDate = 0; // Convert.ToInt32(CookieDate0.Value.ToString().Trim());
        if (CookieDate0.Checked == true)
        {
            iCookieDate = 0;
        }
        else if (CookieDate1.Checked == true)
        {
            iCookieDate = 1;
        }
        else if (CookieDate30.Checked == true)
        {
            iCookieDate = 30;
        }
        else
        {
            iCookieDate = 365;
        }

        string sUserType = "0"; // UserType0.Value.ToString().Trim();
        if (UserType0.Checked == true )
        {
            sUserType = "0";
        }
        else if (UserType1.Checked == true )
        {
            sUserType = "1";
        }

        if (sUserType == "0")  //普通用户
        {
            DataTable MyTb = MyUser.JudgeUserPsd(sUserID, spassword);
            if (MyTb.Rows.Count > 0)
            {
                string sVis = MyTb.Rows[0][0].ToString().Trim();
                if (sVis.ToUpper() == "TRUE")
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户帐户被限制，请与管理员联系！');</script>");
                    return;
                }
                else
                {
                    if (iCookieDate != 0)
                    {
                        Response.Cookies["jusername"].Value = "" + sUserID + "";
                        Response.Cookies["jusername"].Expires = DateTime.Now.AddDays(iCookieDate);
                        Response.Cookies["jpassword"].Value = "" + spassword + "";
                        Response.Cookies["jpassword"].Expires = DateTime.Now.AddDays(iCookieDate);
                        Response.Cookies["jpower"].Value = sVis;
                        Response.Cookies["jpower"].Expires = DateTime.Now.AddDays(iCookieDate);
                        //Response.Cookies["jhidden"].Value=""+Request.Form["hidden"]+"";//不需要选择是否隐身登陆论坛
                        Response.Cookies["jhidden"].Expires = DateTime.Now.AddDays(iCookieDate);
                        Response.Redirect("index.aspx");
                    }
                    else
                    {
                        Response.Cookies["jusername"].Value = "" + sUserID + "";
                        Response.Cookies["jpassword"].Value = "" + spassword + "";
                        Response.Cookies["jpower"].Value = sVis;
                        //Response.Cookies["jhidden"].Value = "" + Request.Form["hidden"] + "";
                        Response.Redirect("index.aspx");
                    }
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('帐户或者密码错误！');</script>");
                return;
            }
        }
        else  //VIP登录
        {
            DataTable MyTb = MyUser.JudgeVIPUserPsd(sUserID, spassword);
            if (MyTb.Rows.Count > 0)
            {
                string sVis = MyTb.Rows[0][0].ToString().Trim();
                if (sVis == "0")
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户帐户被限制，请与管理员联系！');</script>");
                    return;
                }
                else
                {
                    if (iCookieDate != 0)
                    {
                        Response.Cookies["jusername"].Value = "" + sUserID + "";
                        Response.Cookies["jusername"].Expires = DateTime.Now.AddDays(iCookieDate);
                        Response.Cookies["jpassword"].Value = "" + spassword + "";
                        Response.Cookies["jpassword"].Expires = DateTime.Now.AddDays(iCookieDate);
                        Response.Cookies["jpower"].Value = sVis;
                        Response.Cookies["jpower"].Expires = DateTime.Now.AddDays(iCookieDate);
                        //Response.Cookies["jhidden"].Value=""+Request.Form["hidden"]+"";//不需要选择是否隐身登陆论坛
                        Response.Cookies["jhidden"].Expires = DateTime.Now.AddDays(iCookieDate);
                        Response.Redirect("index.aspx");
                    }
                    else
                    {
                        Response.Cookies["jusername"].Value = "" + sUserID + "";
                        Response.Cookies["jpassword"].Value = "" + spassword + "";
                        Response.Cookies["jpower"].Value = sVis;
                        //Response.Cookies["jhidden"].Value = "" + Request.Form["hidden"] + "";
                        Response.Redirect("index.aspx");
                    }
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('帐户或者密码错误！');</script>");
                return;
            }
        }
    }
}
